package cinema;

public class Hall {
    private final String hallName;
    private final int rows;
    private final int columns;
    private final String[][] seatStatus; // 座位状态：O-可售，X-已售

    public Hall(String hallName, int rows, int columns) {
        this.hallName = hallName;
        this.rows = rows;
        this.columns = columns;
        this.seatStatus = initializeSeats(rows, columns);
    }

    // 初始化所有座位为可售状态
    private String[][] initializeSeats(int rows, int columns) {
        String[][] seats = new String[rows][columns];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                seats[i][j] = "O"; // O 表示空座
            }
        }
        return seats;
    }

    // 获取当前座位状态（返回副本防止外部修改）
    public String[][] getSeatsStatus() {
        return copySeatStatus();
    }

    // 更新特定座位状态
    public void updateSeat(int row, int column, String status) {
        if (isValidSeat(row, column)) {
            seatStatus[row][column] = status;
        }
    }

    // 检查座位位置是否有效
    private boolean isValidSeat(int row, int column) {
        return row >= 0 && row < rows && column >= 0 && column < columns;
    }

    // 创建座位状态的深拷贝
    private String[][] copySeatStatus() {
        String[][] copy = new String[rows][columns];
        for (int i = 0; i < rows; i++) {
            System.arraycopy(seatStatus[i], 0, copy[i], 0, columns);
        }
        return copy;
    }

    // Getter 方法
    public String getHallName() {
        return hallName;
    }

    public int getRow() {
        return rows;
    }

    public int getColumn() {
        return columns;
    }
}